package com.tanhua.dubbo.api;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.tanhua.dubbo.mappers.SoulUserMapper;
import com.tanhua.model.domain.SoulUser;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @Description：test
 * @Create by： 张会豪
 * @Date：2021/11/7 20:36
 */
@DubboService
public class SoulUserApiImpl implements SoulUserApi {

    @Autowired
    private SoulUserMapper soulUserMapper;

    //根据userId查询灵魂用户信息
    public SoulUser findByUserId(Long userId) {
        LambdaQueryWrapper<SoulUser> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SoulUser::getId, userId);
        return soulUserMapper.selectOne(queryWrapper);
    }

    //表中数据更新
    public void updateWithScores(SoulUser soulUser) {
        soulUserMapper.updateById(soulUser);
    }

    //表中数据新增
    public void save(SoulUser soulUser) {
        soulUserMapper.insert(soulUser);
    }

    //根据报告id在SoulUser表中查询所有用户id
    public List<Long> finByReportId(Long typeId) {
        LambdaQueryWrapper<SoulUser> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SoulUser::getTypeId, typeId);
        List<SoulUser> soulUsers = soulUserMapper.selectList(queryWrapper);
        return CollUtil.getFieldValues(soulUsers, "id", Long.class);
    }
}
